import {
  add_notes,
  list_notes,
  delete_notes
} from '../../network/interface'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    conduct: [],
    keyword: '',
    images:[]

  },
  changekeyword(e) {
    //改变data上的值
    this.setData({
      keyword: e.detail.value
    })
  },
  addTodo() {
    wx.showLoading({
      title: '发布中'
    })
    var that =this;
    let arr = this.data.images;
    console.log("arr:"+arr[0].path)
  

    wx.uploadFile({
      filePath: arr[0].path,
      name: 'file',
      url: 'https://apibyte.wkhelpme.com/mars/upload/v1/img',
      success(res){
        console.log(JSON.parse(res.data).data)
        let params = {}
        params.notes = that.data.keyword;
        params.image=JSON.parse(res.data).data
        add_notes(params, function success(res) {
          wx.hideLoading({
            success: (res) => {},
          })
          wx.showToast({
            title: '发布成功',
            icon:'none'
          })
          wx.switchTab({
            url: '../myself/myself',
          })
         
        })


      }
    })
    
  },

  chooseimage: function () {
    wx.chooseImage({
      count: 6 - this.data.images.length,
      success: res => {
        this.setData({
          images: this.data.images.concat(res.tempFiles)
        })
      }
    })
  },
  delTodo(e) {
    var that = this;
    let params = {}
    params.id = e.currentTarget.dataset.data.id
    delete_notes(params, res => {
        that.onLoad()
        wx.showToast({
          title: '删除成功',
          icon: 'none',
          duration: 2000
        })
    })
  },

  getListNotes() {
    let params = {}
    list_notes(params, res => {
      this.setData({
        conduct: res.data
      })
      console.log(res.data)
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      keyword:""
    })
    this.setData({
      images: []
      
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      keyword:""
    })
    this.setData({
      images: []
      
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      keyword:""
    })
    this.setData({
      images: []
      
    })
  

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})